package baseFx.tests.database.jdbc;

import baseFx.common.utils.FxDate;
import baseFx.database.DbColumn;
import baseFx.database.Transaction;
import baseFx.database.execute.DbExecute;
import baseFx.database.execute.impl.MysqlExecute;
import baseFx.database.jdbc.impl.MysqlSql;
import baseFx.database.query.DbQuery;
import baseFx.database.query.impl.MysqlQuery;
import com.zaxxer.hikari.HikariDataSource;

import javax.annotation.Resource;
import javax.sql.DataSource;

public class RunMysqlSql {
    public static void main(String[] args) {
        MysqlSql sql = new MysqlSql(getDs());
        DbExecute execute = new MysqlExecute(sql);
        AutoIdx model = execute.insertby(AutoIdx.class, i -> {
            i.idx2 = 2;
            i.idx3 = 3;
        });
        System.out.println(model.idx1);
        System.exit(-1);
    }

    @Resource(name = "pos", description = "allowDelete=true")
    private static class Table {
        public Long id;
        private String sn;

        public String sn() {
            return sn;
        }

        public void sn(String value) {
            sn = value;
        }
    }

    @Resource(name = "auto_idx")
    private static class AutoIdx {
        @Resource(description = "isInc=true")
        public Integer idx1;
        public Integer idx2;
        public Integer idx3;
    }

    private static DataSource getDs() {
        HikariDataSource ds = new HikariDataSource();
        ds.setJdbcUrl("jdbc:mysql://192.168.1.55:3306/daifu?useUnicode=true&characterEncoding=UTF8&allowMultiQueries=true&serverTimezone=GMT%2B8");
        ds.setUsername("dev");
        ds.setPassword("123456");
        ds.setMaximumPoolSize(10);
        ds.setConnectionTimeout(FxDate.toMillisBySeconds(10));
        return ds;
    }
}
